package com.ruoyi.camp.service.impl;

import java.util.List;

import com.ruoyi.camp.mapper.CDetailsMapper;
import com.ruoyi.camp.service.ICDetailsService;
import com.ruoyi.common.utils.uuid.IdUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.camp.mapper.CAppointmentMapper;
import com.ruoyi.camp.domain.CAppointment;
import com.ruoyi.camp.service.ICAppointmentService;

/**
 * 营地预约Service业务层处理
 *
 * @author ruoyi
 * @date 2024-11-26
 */
@Service
public class CAppointmentServiceImpl implements ICAppointmentService {
    @Autowired
    private CAppointmentMapper cAppointmentMapper;

    @Autowired
    private ICDetailsService icDetailsService;
    /**
     * 查询营地预约
     *
     * @param appointmentid 营地预约主键
     * @return 营地预约
     */
    @Override
    public CAppointment selectCAppointmentByAppointmentid(String appointmentid) {
        return cAppointmentMapper.selectCAppointmentByAppointmentid(appointmentid);
    }

    /**
     * 查询营地预约列表
     *
     * @param cAppointment 营地预约
     * @return 营地预约
     */
    @Override
    public List<CAppointment> selectCAppointmentList(CAppointment cAppointment) {
        return cAppointmentMapper.selectCAppointmentList(cAppointment);
    }

    /**
     * 新增营地预约
     *
     * @param cAppointment 营地预约
     * @return 结果
     */
    @Override
    public int insertCAppointment(CAppointment cAppointment) {
        cAppointment.setAppointmentid(IdUtils.randomUUID());
        for (int i = 0; cAppointment.getDetailsList() != null && i < cAppointment.getDetailsList().size(); i++) {
            cAppointment.getDetailsList().get(i).setAppointid(cAppointment.getAppointmentid());
            cAppointment.getDetailsList().get(i).setDetailid(IdUtils.randomUUID());
            icDetailsService.insertCDetails(cAppointment.getDetailsList().get(i));
        }
        return cAppointmentMapper.insertCAppointment(cAppointment);
    }

    /**
     * 修改营地预约
     *
     * @param cAppointment 营地预约
     * @return 结果
     */
    @Override
    public int updateCAppointment(CAppointment cAppointment) {
        icDetailsService.deleteDetailsByAppointid(cAppointment.getAppointmentid());
        for (int i = 0; i < cAppointment.getDetailsList().size(); i++) {
            cAppointment.getDetailsList().get(i).setAppointid(cAppointment.getAppointmentid());
            cAppointment.getDetailsList().get(i).setDetailid(IdUtils.randomUUID());
            icDetailsService.insertCDetails(cAppointment.getDetailsList().get(i));
        }
        return cAppointmentMapper.updateCAppointment(cAppointment);
    }

    /**
     * 批量删除营地预约
     *
     * @param appointmentids 需要删除的营地预约主键
     * @return 结果
     */
    @Override
    public int deleteCAppointmentByAppointmentids(String[] appointmentids) {
        return cAppointmentMapper.deleteCAppointmentByAppointmentids(appointmentids);
    }

    /**
     * 删除营地预约信息
     *
     * @param appointmentid 营地预约主键
     * @return 结果
     */
    @Override
    public int deleteCAppointmentByAppointmentid(String appointmentid) {
        return cAppointmentMapper.deleteCAppointmentByAppointmentid(appointmentid);
    }
}
